package com.lzx.iteam.net;

import android.content.Context;
import android.os.Message;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by Megan on 15/12/23.
 */
public class GetCloudContactTalkPreViewMsg extends CcMsgStructure {
    private Context mmContext;
    private Message mmCallback;

    public GetCloudContactTalkPreViewMsg(Context context, Message message) {
        mmContext = context;
        mmCallback = message;
    }

    @Override
    public void onReceive(JSONObject jsonObject) {
        ArrayList<String> list = new ArrayList<String>();
        try {
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            for (int i=0;i<jsonArray.length();i++){
                list.add((String)jsonArray.get(i));
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (mmCallback != null) {
            mmCallback.arg1 = 0;
            mmCallback.obj = list;
            mmCallback.sendToTarget();
        }
    }

    @Override
    public void onError(int error, Object ret) {
        if (mmCallback != null) {
            mmCallback.arg1 = error;
            mmCallback.sendToTarget();
        }
    }
}
